"use strict";
cc._RF.push(module, 'ca1a81tJchLJpXR4seSCIhA', 'KuaiShaoAd');
// scripts/KuaiShaoAd.js

"use strict";

var e = require;
var t = module;
var o = exports;

var _ii,
    nn = void 0 && (void 0).__extends || (_ii = function ii(t, e) {
  return (_ii = Object.setPrototypeOf || {
    __proto__: []
  } instanceof Array && function (t, e) {
    t.__proto__ = e;
  } || function (t, e) {
    for (var o in e) {
      Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
    }
  })(t, e);
}, function (t, e) {
  function o() {
    this.constructor = t;
  }

  _ii(t, e), t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o());
}),
    rr = void 0 && (void 0).__awaiter || function (t, e, o, i) {
  return new (o || (o = Promise))(function (n, a) {
    function r(t) {
      try {
        l(i.next(t));
      } catch (e) {
        a(e);
      }
    }

    function s(t) {
      try {
        l(i["throw"](t));
      } catch (e) {
        a(e);
      }
    }

    function l(t) {
      var e;
      t.done ? n(t.value) : (e = t.value, e instanceof o ? e : new o(function (t) {
        t(e);
      })).then(r, s);
    }

    l((i = i.apply(t, e || [])).next());
  });
};

var oo = void 0 && (void 0).__decorate || function (e, t, a, n) {
  var i,
      o = arguments.length,
      s = o < 3 ? t : null === n ? n = Object.getOwnPropertyDescriptor(t, a) : n;
  if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, a, n);else for (var r = e.length - 1; r >= 0; r--) {
    (i = e[r]) && (s = (o < 3 ? i(s) : o > 3 ? i(t, a, s) : i(t, a)) || s);
  }
  return o > 3 && s && Object.defineProperty(t, a, s), s;
};

Object.defineProperty(o, "__esModule", {
  value: !0
});
var a = e("sdkConfig"),
    n = e("AdInterface"),
    i = cc._decorator,
    r = i.ccclass,
    s = (i.property, function (e) {
  function t() {
    var t = null !== e && e.apply(this, arguments) || this;
    return t.game_version = "101", t.app_test_version = !1, t.videoAd = null, t.loadSucc_Video = null, t.callback_Video = null, t.systemIntersAd = null, t.loadSucc_SystemInters = !1, t.NUM_SystemIntersLoadError = 0, t.NUM_IntersNowIntervalTime = 0, t.NUM_hasShowInters = 0, t.NUN_hasVideoShowInters = 0, t.NUM_IntersNowToAddDesktop = 0, t.NUM_intersNowInterval = 0, t;
  }

  return nn(t, e), t.prototype.GameVersion = function (e) {
    this.app_test_version = this.game_version == e;
  }, t.prototype.getGameTestVersion = function () {
    return this.app_test_version;
  }, t.prototype.createAd = function () {
    this.SW_Video && "" != this.ID_Video && this.createVideo(), this.SW_System_Inters && "" != this.ID_System_Inters && this.createSystemInters(), this.NUM_IntersIntervalTime > 0 && this.runIntersInterval();
  }, t.prototype.createVideo = function () {
    var e = this;
    a["default"].stringHasSpace(this.ID_Video) ? console.log(a["default"].GameName + "********当前渠道视频广告ID中含有空字符串,请检查后台视频广告ID*********************") : (this.videoAd = ks.createRewardedVideoAd({
      adUnitId: this.ID_Video
    }), this.videoAd.onError(function (t) {
      console.log("快手 视频加载失败：", JSON.stringify(t)), e.callback_Video && (e.callback_Video(null), e.callback_Video = null), e.loadSucc_Video = !1, setTimeout(function () {
        e.videoAd && e.videoAd.load();
      }, 3e3);
    }), this.videoAd && (this.loadSucc_Video = !0, this.videoAd.onClose(function (t) {
      t && t.isEnded || void 0 === t ? (e.callback_Video(!0), e.callback_Video = null) : (e.callback_Video(!1), e.callback_Video = null), e.loadSucc_Video = !1, setTimeout(function () {
        e.videoAd && e.videoAd.load();
      }, 3e3);
    })));
  }, t.prototype.getVideoFlag = function () {
    return this.loadSucc_Video;
  }, t.prototype.showVideo = function (e) {
    this.videoAd && this.loadSucc_Video && (this.callback_Video = e, this.videoAd.show()["catch"](function (e) {
      return console.log("快手 视频播放错误", e);
    }));
  }, t.prototype.createSystemInters = function () {
    var e = this;
    a["default"].stringHasSpace(this.ID_System_Inters) ? console.log("当前渠道系统插屏广告ID中含有空字符串,请检查后台系统插屏广告ID*********************") : (this.systemIntersAd = ks.createInterstitialAd({
      adUnitId: this.ID_System_Inters
    }), this.loadSucc_SystemInters = !0, this.systemIntersAd.onError(function (t) {
      e.NUM_SystemIntersLoadError++, e.loadSucc_SystemInters = !1, console.log(e.NUM_SystemIntersLoadError, "快手 系统插屏加载失败：", JSON.stringify(t)), e.NUM_SystemIntersLoadError < 5 && setTimeout(function () {
        e.createSystemInters();
      }, 1e4);
    }), this.systemIntersAd.onClose(function () {
      console.log("快手 系统插屏广告关闭"), e.NUM_IntersNowIntervalTime = 0, e.loadSucc_SystemInters = !1, setTimeout(function () {
        e.createSystemInters();
      }, 4e3);
    }));
  }, t.prototype.getIntersFlag = function () {
    return this.loadSucc_SystemInters;
  }, t.prototype.showInters = function () {
    var e = this;

    if (this.getIntersFlag()) {
      if (console.log("快手 展示插屏广告"), this.NUM_hasShowInters++, this.SW_Inters_Desk && this.NUM_hasShowInters <= this.Inters_Add_Num && (console.log("快手 第" + this.Inters_Add_Num + "次插屏变添加桌面", "当前第" + this.NUM_hasShowInters + "次"), this.NUM_hasShowInters == this.Inters_Add_Num)) this.getAddDesktopFlag(function (t) {
        t && (console.log("快手 插屏变添加桌面"), e.addDesktop(function () {}));
      });else {
        if (!this.getGameTestVersion() && this.Control_Video && this.Control_Inters_To_Video_Switch && this.NUN_hasVideoShowInters > 0) {
          if (console.log("快手 第" + this.Control_Start_Inters_To_Video + "次插屏变视频", "当前第" + this.NUN_hasVideoShowInters + "次"), this.Control_Start_Inters_To_Video > 0 && this.NUN_hasVideoShowInters == this.Control_Start_Inters_To_Video) return console.log("快手 首次插屏变视频"), this.NUN_hasVideoShowInters++, void this.showVideo(function () {});
          if (this.Control_Inters_To_Video > 0 && this.NUN_hasVideoShowInters % this.Control_Inters_To_Video == 0) return console.log("快手 间隔插屏变视频"), this.NUN_hasVideoShowInters++, void this.showVideo(function () {});
        }

        if (this.Control_Inters) {
          if (this.NUM_hasShowInters < this.Control_Start_Num) return void console.log("快手 插屏开始次数未达到", this.NUM_hasShowInters, "目标次数", this.Control_Start_Num);
          if (this.NUM_intersNowInterval < this.Control_Interval_Num) return console.log("快手 插屏间隔次数未达到", this.NUM_intersNowInterval, "目标次数", this.Control_Interval_Num), void this.NUM_intersNowInterval++;
          if (this.NUM_IntersNowIntervalTime < this.Control_Interval_Time) return console.log("快手 插屏间隔时间未达到", this.NUM_IntersNowIntervalTime, "目标时间", this.Control_Interval_Time), void (this.SW_Inters_Desk && this.NUM_IntersNowToAddDesktop < this.Inters_Add_Num && this.getAddDesktopFlag(function (t) {
            t && (e.NUM_IntersNowToAddDesktop++, e.addDesktop(function () {
              console.log("快手 插屏间隔弹桌面");
            }));
          }));
        }

        this.NUM_intersNowInterval = 0, this.Control_Delay_Time > 0 && Math.floor(100 * Math.random()) < this.Control_Delay_Prob ? (console.log("插屏延迟时间(ms):" + this.Control_Delay_Time), setTimeout(function () {
          e.loadSucc_SystemInters && e.showSystemInters();
        }, this.Control_Delay_Time)) : this.loadSucc_SystemInters && this.showSystemInters(), this.NUN_hasVideoShowInters++;
      }
    } else console.log("快手  插屏广告暂未开启************请在后台确认是否开启***************");
  }, t.prototype.showSystemInters = function () {
    this.systemIntersAd && this.loadSucc_SystemInters && this.systemIntersAd.show();
  }, t.prototype.runIntersInterval = function () {
    var e = this;
    this.NUM_IntersIntervalTime > 0 && setInterval(function () {
      e.NUM_IntersNowIntervalTime++;
    }, 1e3);
  }, t.prototype.setGroup = function (e) {
    this.AdGroup = e;
  }, t.prototype.hasAddDesktopFunc = function () {
    return !0;
  }, t.prototype.getAddDesktopFlag = function (e) {
    ks.getAPKShortcutInstallStatus(function (t) {
      -10005 === t.code ? e(!1) : 1 === t.code ? t.installed || e(!0) : e(!1);
    });
  }, t.prototype.addDesktop = function (e) {
    ks.saveAPKShortcut(function (t) {
      -10005 === t.code ? e(!1) : 1 === t.code ? e(!0) : (e(!1), console.log("快手 添加桌面错误：", JSON.stringify(t.msg)));
    });
  }, oo([r], t);
}(n["default"]));
o["default"] = s;

cc._RF.pop();